package com.platform.upms.controller;

import com.platform.common.config.Global;
import com.platform.upms.model.UpmsMenu;
import com.platform.upms.model.UpmsUser;
import com.platform.upms.service.UpmsMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class IndexController {

    @Autowired
    UpmsMenuService upmsMenuService;

    /**
     * 加载登录后的首页，查询菜单
     * @param modelMap
     * @return
     */
    @RequestMapping(value="/" ,method = RequestMethod.GET)
    public String index(ModelMap modelMap, HttpSession session){
        List<UpmsMenu> list = upmsMenuService.listMenuByUserId(((UpmsUser)session.getAttribute(Global.UPMSUSER)).getId());
        modelMap.put("menuList",list);
        return "/index.jsp";
    }

    /**
     * 加载菜单中的第一个页面
     * @param modelMap
     * @return
     */
    @RequestMapping(value="/home" ,method = RequestMethod.GET)
    public String home(ModelMap modelMap) {
            return "/body/home.jsp";
    }
}
